﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL.Artwork;

namespace WebApplication
{
    public partial class Arts : System.Web.UI.Page
    {
        public int totalCount = -1;

        public int pageIndex = 1;

        public int pageSize = 36;

        private ArtworkService artworkService = new ArtworkService();

        public List<Models.Artworks> artworks = new List<Models.Artworks>();

        protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.QueryString["type"];
            string style = Request.QueryString["style"];
            string pageNo = Request.QueryString["pageIndex"];
            string order = "CreatedAt Desc";

            if(string.IsNullOrEmpty(type))
            {
                type = "@";
            }

            if(string.IsNullOrEmpty(style))
            {
                style = "@";
            }

            string[] tags = new string[] { type, style };


            if (!String.IsNullOrEmpty(pageNo))
            {
                pageIndex = Convert.ToInt32(pageNo);
            }

            if(!String.IsNullOrEmpty(Request.QueryString["order"]))
            {
                order = Request.QueryString["order"] + " Desc";
            }

            artworks = artworkService.GetList(ref totalCount, tags, pageIndex, pageSize, order);

            if (Session["UID"] != null)
            {
                int uid = Convert.ToInt32(Session["UID"]);
                artworkService.QueryIsLiked(uid, artworks);
            }
        }
    }
}